﻿namespace Example.IO
{
    using System;
    using System.Globalization;
    using System.IO;
    using System.Text;
    using Xunit;

    public class EncodedStringWriterFacts
    {
        [Fact]
        public void ctor_StringBuilder()
        {
            Assert.NotNull(new EncodedStringWriter(new StringBuilder()));
        }

        [Fact]
        public void ctor_StringBuilderNull()
        {
            Assert.Throws<ArgumentNullException>(() => new EncodedStringWriter(null));
        }

        [Fact]
        public void ctor_StringBuilderNull_Encoding()
        {
            Assert.Throws<ArgumentNullException>(() => new EncodedStringWriter(null, Encoding.UTF8));
        }

        [Fact]
        public void ctor_StringBuilderNull_IFormatProvider_Encoding()
        {
            Assert.Throws<ArgumentNullException>(() => new EncodedStringWriter(null, CultureInfo.InvariantCulture, Encoding.UTF8));
        }

        [Fact]
        public void ctor_StringBuilder_Encoding()
        {
            Assert.NotNull(new EncodedStringWriter(new StringBuilder(), Encoding.UTF8));
        }

        [Fact]
        public void ctor_StringBuilder_EncodingNull()
        {
            Assert.Throws<ArgumentNullException>(() => new EncodedStringWriter(new StringBuilder(), null));
        }

        [Fact]
        public void ctor_StringBuilder_IFormatProviderNull_Encoding()
        {
            Assert.NotNull(new EncodedStringWriter(new StringBuilder(), null, Encoding.UTF8));
        }

        [Fact]
        public void ctor_StringBuilder_IFormatProvider_Encoding()
        {
            Assert.NotNull(new EncodedStringWriter(new StringBuilder(), CultureInfo.InvariantCulture, Encoding.UTF8));
        }

        [Fact]
        public void ctor_StringBuilder_IFormatProvider_EncodingNull()
        {
            Assert.Throws<ArgumentNullException>(() => new EncodedStringWriter(new StringBuilder(), CultureInfo.InvariantCulture, null));
        }

        [Fact]
        public void is_StringWriter()
        {
            Assert.IsAssignableFrom<StringWriter>(new EncodedStringWriter(new StringBuilder()));
        }

        [Fact]
        public void prop_Encoding()
        {
            var expected = Encoding.UTF8;
            var actual = new EncodedStringWriter(new StringBuilder()).Encoding;

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void prop_Encoding_utf8()
        {
            var expected = Encoding.UTF8;
            var actual = new EncodedStringWriter(new StringBuilder(), Encoding.UTF8).Encoding;

            Assert.Equal(expected, actual);
        }
    }
}